package com.inossem.warehousestorage_inossem.adapter.groupUpFrame;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.TextView;

import com.inossem.utils.listener.NoDoubleClickListener;
import com.inossem.warehousestorage_inossem.R;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者：wsy on 2018/1/31 11:35
 * <p>
 * 邮箱：445979770@qq.com
 */

public class GroupUpFrameSearchMaterialAdapter extends BaseAdapter {

    private Context mContext;
    private LayoutInflater inflater;
    private String mCondition;
    private ViewHolder viewHolder;
    private List<String> list;
    private String choose = "1";

    public GroupUpFrameSearchMaterialAdapter (Context context , String condition) {
        this.mContext = context;
        this.mCondition = condition;
        inflater = LayoutInflater.from(context);
        list = new ArrayList<>();
        for (int i = 0; i < 6; i++) {
            list.add("1");
        }
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int postiton) {
        return list.get(postiton);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int postiton, View convertView, ViewGroup viewGroup) {
        if (postiton == 0) {
            convertView = inflater.inflate(R.layout.view_group_up_frame_search_material_list_first_item, null);
            EditText condition = (EditText) convertView.findViewById(R.id.condition);
            condition.setHint(mContext.getResources().getString(R.string.activity_group_up_frame_search_material_enter_batch_code));
            condition.setText(mCondition);
            TextView batchCode = (TextView) convertView.findViewById(R.id.batchCode);
            TextView materialCode = (TextView) convertView.findViewById(R.id.materialCode);
            TextView materialDescribe = (TextView) convertView.findViewById(R.id.materialDescribe);
            View batchCodeView = convertView.findViewById(R.id.batchCodeView);
            batchCodeView.setBackgroundColor(mContext.getResources().getColor(R.color.include_header_background));
            View materialCodeView = convertView.findViewById(R.id.materialCodeView);
            View materialDescribeView = convertView.findViewById(R.id.materialDescribeView);
            batchCode.setOnClickListener(new NoDoubleClickListener() {
                @Override
                public void onNoDoubleClick(View v) {
                    if (!choose.equals("1")) {
                        batchCodeView.setBackgroundColor(mContext.getResources().getColor(R.color.include_header_background));
                        materialCodeView.setBackgroundColor(mContext.getResources().getColor(R.color.base_white));
                        materialDescribeView.setBackgroundColor(mContext.getResources().getColor(R.color.base_white));
                        condition.setHint(mContext.getResources().getString(R.string.activity_group_up_frame_search_material_enter_batch_code));
                        choose = "1";
                    }
                }
            });

            materialCode.setOnClickListener(new NoDoubleClickListener() {
                @Override
                public void onNoDoubleClick(View v) {
                    if (!choose.equals("2")) {
                        materialCodeView.setBackgroundColor(mContext.getResources().getColor(R.color.include_header_background));
                        batchCodeView.setBackgroundColor(mContext.getResources().getColor(R.color.base_white));
                        materialDescribeView.setBackgroundColor(mContext.getResources().getColor(R.color.base_white));
                        condition.setHint(mContext.getResources().getString(R.string.activity_group_up_frame_search_material_enter_material_code));
                        choose = "2";
                    }
                }
            });
            materialDescribe.setOnClickListener(new NoDoubleClickListener() {
                @Override
                public void onNoDoubleClick(View v) {
                    if (!choose.equals("3")) {
                        materialDescribeView.setBackgroundColor(mContext.getResources().getColor(R.color.include_header_background));
                        batchCodeView.setBackgroundColor(mContext.getResources().getColor(R.color.base_white));
                        materialCodeView.setBackgroundColor(mContext.getResources().getColor(R.color.base_white));
                        condition.setHint(mContext.getResources().getString(R.string.activity_group_up_frame_search_material_enter_material_describe));
                        choose = "3";
                    }
                }
            });

        }else {
            if (convertView == null || (convertView != null && convertView.getTag() == null)) {
                convertView = inflater.inflate(R.layout.view_group_up_frame_group_material_list, null);
                viewHolder = new ViewHolder();
                //初始化控件
                initView(viewHolder, convertView);
                convertView.setTag(viewHolder);
            } else {
                viewHolder = (ViewHolder) convertView.getTag();
            }
            //初始化数据
            initData(mContext, viewHolder, convertView);
        }
        return convertView;
    }

    private void initView(ViewHolder viewHolder, View convertView) {
        viewHolder.batch = (TextView) convertView.findViewById(R.id.batch);
        viewHolder.materialCode = (TextView) convertView.findViewById(R.id.materialCode);
        viewHolder.materielDescribe = (TextView) convertView.findViewById(R.id.materielDescribe);
        viewHolder.totalNumber = (TextView) convertView.findViewById(R.id.totalNumber);
        viewHolder.shelves = (EditText) convertView.findViewById(R.id.shelves);
    }
    private void initData(Context mContext, ViewHolder viewHolder, View convertView) {
        viewHolder.batch.setText("1000070646");
        viewHolder.materialCode.setText("60000648");
        viewHolder.materielDescribe.setText("普通钢丝绳/6*19#18.5/FC 0");
        viewHolder.totalNumber.setText("待上架20TON");
        viewHolder.shelves.setText("本次上架20TON");
    }

    private class ViewHolder{
        private TextView batch , materialCode , materielDescribe , totalNumber ;
        private EditText shelves;
    }
}
